package com.wd.tech.activity.adaptert;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.wd.tech.R;
import com.wd.tech.activity.bean.MorvBean;

import java.util.List;

import io.reactivex.Observer;

/**
 * @author 时文豪
 * @description: 更多
 * @date :2020/7/3 14:28
 */
public class MoreAdaptert extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    Context context;
    List<MorvBean.ResultBean> list;
    private setOnClick click;

    public MoreAdaptert(Context context, List<MorvBean.ResultBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = View.inflate(context, R.layout.morv_item, null);
        return new MyMorv(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        ((MyMorv) holder).morv_name.setText(list.get(position).getName());
        Glide.with(context).load(list.get(position).getPic()).apply(RequestOptions.bitmapTransform(new RoundedCorners(20)))
                .into(((MyMorv) holder).morv_img);
        ((MyMorv) holder).morv_img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                click.ck(list.get(position).getId());
            }
        });
    }

    public void setOnClick(setOnClick onClick) {
        click = onClick;
    }

    public interface setOnClick {
        void ck(int id);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyMorv extends RecyclerView.ViewHolder {

        private final ImageView morv_img;
        private final TextView morv_name;

        public MyMorv(@NonNull View itemView) {
            super(itemView);
            morv_img = itemView.findViewById(R.id.morv_img);
            morv_name = itemView.findViewById(R.id.morv_name);
        }
    }
}
